package com.apps.gomdiem.fragment;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.apps.gomdiem.R;
import com.apps.gomdiem.adapter.ListViewAdapter;
import com.apps.gomdiem.adapter.GridAdapter.ViewHolder;
import com.apps.gomdiem.fragment.MenuTabFragment.OnCheckBoxClickedListener;
import com.apps.gomdiem.hardcode.MyHardCode;
import com.apps.gomdiem.helper.DataBaseHelper;
import com.apps.gomdiem.model.MainModel;
import com.apps.gomdiem.model.MenuList;
import com.apps.gomdiem.model.Store;

public class MenuDetailFragment extends Fragment{
	
	private String key;
	private OnCheckBoxClickedListener onCallBack;
	
	
	public static MenuDetailFragment getnewInstance(String text, OnCheckBoxClickedListener onCallBack) {
		MenuDetailFragment menuFragment = new MenuDetailFragment();
	    Bundle bundle = new Bundle();
	    bundle.putString("test", text);
	    
	    menuFragment.setArguments(bundle);
	    menuFragment.setCallBack(onCallBack);

	    return menuFragment;
	}

	
	public void setCallBack(OnCheckBoxClickedListener onCallBack){
		this.onCallBack = onCallBack;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		key = getArguments().getString("test");
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		ListView listview = new ListView(getActivity());
		listview.setAdapter(getAdapter());
		
		return listview;
	}
	
	
	
	
	private BaseAdapter getAdapter(){
		
		ArrayList<MenuList> arrayMenuList;
		if(key.equals("menu1")){
			String mIdStore = MainModel.getInstant().getIdStore();
			DataBaseHelper db = new DataBaseHelper(getActivity());
			arrayMenuList =db.getAllMenu(mIdStore);
			return new ListViewAdapter(arrayMenuList,getActivity(), onCallBack); //Khoahm: truyền callback của mình vào qua tiếp lớp này luôn ( cái phần xử lý đó )
		}
		
		else if (key.equals("menu2")) {
			return new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new String[] { "A2", "B2", "C2", "D2" });
		}
		else if (key.equals("menu3")) {
			return new ArrayAdapter<String>(getActivity(),
					android.R.layout.simple_list_item_1, new String[] { "A3", "B3",
					"C3", "D3" });
		}
		
		
		return null;
	}

}
